package cn.wolfcode.shop.cloud.mq.listener;

import cn.wolfcode.shop.cloud.common.JSONUtil;
import cn.wolfcode.shop.cloud.common.Result;
import cn.wolfcode.shop.cloud.mq.MQConstants;
import cn.wolfcode.shop.cloud.mq.msg.SeckillFailedMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * Created by wolfcode-lanxw
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = MQConstants.SECKILL_ORDER_TOPIC,
        selectorExpression = MQConstants.SECKILL_FAILED_TAG,
        consumerGroup = MQConstants.SECKILL_FAILED_CONSUMER_GROUP
)
public class SeckillFailedMQListener extends AbstractResultNotifyMQListener implements RocketMQListener<SeckillFailedMsg> {

    @Override
    public String getLogTag() {
        return "[秒杀失败通知]";
    }

    @Override
    public void onMessage(SeckillFailedMsg message) {
        log.info("{} 收到消息:{}", getLogTag(), JSONUtil.toJSONString(message));

        // 调用父类的公共方法
        super.sendMessage(message.getUuid(), Result.error(message.getCodeMsg()));
    }
}
